extern char *tzname[2]; void tzset() void tzsetwall() char *ctime(clock) long *clock; #include <time.h> char *asctime(tm) struct tm *tm; struct tm *localtime(clock) long *clock; struct tm *gmtime(clock) long *clock; cc ... -lz
Tzsetwall sets things up so that localtime returns the best available approximation of local wall clock time.
Ctime
converts a long integer, pointed to by
clock,
representing the time in seconds since
00:00:00 GMT, January 1, 1970,
and returns a pointer to a
26-character string
of the form
Localtime and gmtime return pointers to ``tm'' structures, described below. Localtime corrects for the time zone and any time zone adjustments (such as Daylight Savings time in the U.S.A.). Before doing so, localtime calls tzset (if tzset has not been called in the current process). After filling in the ``tm'' structure, localtime sets the tm_isdst'th element of tzname to a pointer to an ASCII string that's the time zone abbreviation to be used with localtime's return value.
Gmtime converts to Greenwich Mean Time (GMT).
Asctime converts a time value contained in a ``tm'' structure to a 26-character string, as shown in the above example, and returns a pointer to the string.
Declarations of all the functions and externals, and the ``tm'' structure, are in the <time.h> header file. The structure (of type) struct tm includes the following fields:
int tm_sec; /* seconds (0 - 59) */ int tm_min; /* minutes (0 - 59) */ int tm_hour; /* hours (0 - 23) */ int tm_mday; /* day of month (1 - 31) */ int tm_mon; /* month of year (0 - 11) */ int tm_year; /* year - 1900 */ int tm_wday; /* day of week (Sunday = 0) */ int tm_yday; /* day of year (0 - 365) */ int tm_isdst; /* is DST in effect? */ char *tm_zone; /* abbreviation of timezone name */ long tm_gmtoff; /* offset from GMT in seconds */
The tm_zone and tm_gmtoff fields exist, and are filled in, only if arrangements to do so were made when the library containing these functions was created. There is no guarantee that these fields will continue to exist in this form in future releases of this code.
Tm_isdst is non-zero if a time zone adjustment such as Daylight Savings time is in effect.
Tm_gmtoff is the offset (in seconds) of the time represented from GMT, with positive values indicating East of Greenwich.